package com.bookSystem.servlet;/*
 * @Author:lsx
 * @Date:2024/9/16--09--16--16:29
 *
 */

import com.bookSystem.service.Impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        UserServiceImpl userService = new UserServiceImpl();
        String username = request.getParameter("userName");
        String password = request.getParameter("password");
        String account = request.getParameter("account");

        int register = userService.register(username, password, account);
        if (register == 2) {
            request.setAttribute("msg", "注册成功");
            request.getRequestDispatcher("login.jsp").forward(request,response);
        } else {
            request.setAttribute("msg", "注册失败");
            request.getRequestDispatcher("register.jsp").forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
